local more1__taoyuan = fk.CreateSkill{
  name = "more1__taoyuan",
  tags = { Skill.Compulsory, },
}
Fk:loadTranslationTable{
  ["more1__taoyuan"] = "桃园",
  [":more1__taoyuan"] = "锁定技，当你体力减少后或你进入濒死，"..
  "你从牌顶堆亮出X张牌，若亮出的牌颜色不全为黑色，则你将体力回复到1(未进入濒死不回复)，"..
  "然后你指定一名角色，令其从三张未登场的蜀势力武将牌中选择一名获得上面所有技能。(X为场上蜀势力角色的数量)",
  ["#more1__taoyuan-ask"] = "选择一名角色令其获得技能"
}
more1__taoyuan:addEffect(fk.EnterDying, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(more1__taoyuan.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    for _, p in ipairs(room.alive_players) do
      if p.kingdom == "shu" then
        n = n + 1
      end
    end
    if n > 0 then 
      local cards = room:getNCards(n)
      room:turnOverCardsFromDrawPile(player, cards, more1__taoyuan.name)
      local m = 0
      for _, ids in ipairs(cards) do
        if Fk:getCardById(ids).color ~= Card.Black then 
          m = m +1
        end
      end
      if m > 1 and player.hp < 1 then
        room:recover{
          who = player,
          num = 1-player.hp,
          skillName = more1__taoyuan.name,
        }
      end
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, more1__taoyuan.name, nil, true, player.id) 
  end

    local to = room:askToChoosePlayers(player, {
      targets = room.alive_players,
      min_num = 1,
      max_num = 1,
      prompt = "#more1__taoyuan-ask",
      skill_name = more1__taoyuan.name,
      cancelable = false,
    })

    if #to == 0 then return false end

    local generals = table.filter(room.general_pile, function (general_name)
      local general = Fk.generals[general_name]
      return general.kingdom == "shu"
    end)
    if #generals > 0 then
      generals = table.random(generals, 3)
      local general = Fk.generals[room:askToChooseGeneral(
        to[1],
        {
          generals = generals,
          n = 1,
          no_convert = true,
        }
      )]

      local skills = general:getSkillNameList(player.role == "lord" and #room.players > 4)
      room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, false)
    end
  end,
})



more1__taoyuan:addEffect(fk.HpChanged, {
  can_trigger = function(self, event, target, player, data)
    return target == player and data.num < 0 and player:hasSkill(more1__taoyuan.name) and player.hp > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    for _, p in ipairs(room.alive_players) do
      if p.kingdom == "shu" then
        n = n + 1
      end
    end
    if n > 0 then 
      local cards = room:getNCards(n)
      room:turnOverCardsFromDrawPile(player, cards, more1__taoyuan.name)
      local m = 0
      for _, ids in ipairs(cards) do
        if Fk:getCardById(ids).color ~= Card.Black then 
          m = m +1
        end
      end
      if m > 0 and player.hp < 1 then
        room:recover{
          who = player,
          num = 1-player.hp,
          skillName = more1__taoyuan.name,
        }
      end
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, more1__taoyuan.name, nil, true, player.id)
    end
    local to = room:askToChoosePlayers(player, {
      targets = room.alive_players,
      min_num = 1,
      max_num = 1,
      prompt = "#more1__taoyuan-ask",
      skill_name = more1__taoyuan.name,
      cancelable = false,
    })

    if #to == 0 then return end

    local generals = table.filter(room.general_pile, function (general_name)
      local general = Fk.generals[general_name]
      return general.kingdom == "shu"
    end)
    if #generals > 0 then
      generals = table.random(generals, 3)
      local general = Fk.generals[room:askToChooseGeneral(
        to[1],
        {
          generals = generals,
          n = 1,
          no_convert = true,
        }
      )]

      local skills = general:getSkillNameList(player.role == "lord" and #room.players > 4)
      room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, false)
    end
  end,
})




return more1__taoyuan